
;{--- TEST ---------------------------------------------------------------------------------------------------
/*
global COBRA := A_ScriptDir "\.."

i := new CConfig()

msgbox % i.path.ini
*/
;}



class CConfig
{
	static Version := "2.1.0"
	
	
	__New(iniPath = "")
	{
		this.Path := new this.CPaths(iniPath)
	}
	
	
	
	class CPaths
	{				
		static UserFunctions := A_ScriptDir "\user\user_functions.ahk"
		static AppData       := A_ScriptDir "\c0bra_info.ini"
		static DropBox       := this.GetDropbox()
		
		__New(iniPath = "")
		{
			this.INI := iniPath ? iniPath : COBRA "\user\user_settings.ini"
		}
		
		
		;--------------------------------------------------------------------
		; Function: GetDropbox
		;	Returns the full path to the Dropbox folder on the
		;	user's machine, if it exists.
		;--------------------------------------------------------------------
		GetDropbox()
		{
			RegRead, Key,  HKEY_CURRENT_USER,  Software\Dropbox\, InstallPath
			FileReadLine, Key, % SubStr(Key, 1, -3) . "host.db",  2		
			return this.InvBase64(key)
		}
		
	 
		;--------------------------------------------------------------------
		; Function: InvBase
		;	Helper function that converts from a base64 value to a string
		;--------------------------------------------------------------------
		InvBase64(code) 
		{
			Chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 
			StringReplace code, code, =,,All 
			Loop Parse, code 
			{
				If Mod(A_Index,4) = 1 
					buffer := InStr(Chars,A_LoopField,1) - 1 << 18
				Else If Mod(A_Index,4) = 2 
					buffer += InStr(Chars,A_LoopField,1) - 1 << 12 
				Else If Mod(A_Index,4) = 3 
					buffer +=  InStr(Chars,A_LoopField,1) - 1<< 6 
				Else { 
					buffer +=  InStr(Chars,A_LoopField,1) - 1
					out := out . Chr(buffer>>16) . Chr(255 & buffer>>8) . Chr(255 & buffer) 
				} 
			}
			If Mod(StrLen(code),4) = 0 
				Return out 
			If Mod(StrLen(code),4) = 2 
				Return out . Chr(buffer>>16) 
			Return out . Chr(buffer>>16) . Chr(255 & buffer>>8) 
		}
	
	}
		
	
  
	
	
}

